#pragma once

#include <string>
#include <vector>

struct _xmlDoc;
struct _xmlNode;

namespace liba {
namespace xml {
namespace parser {

struct Node
{
	_xmlNode *node;
	Node(_xmlNode *node): node(node) {}

	std::string GetAttribute(const std::string &name) const;
	std::string GetValue() const;
	Node GetNode(const std::string &name) const;
	std::vector <Node> GetNodes(const std::string &name) const;

	_xmlNode* operator ->() { return node; }
	bool operator !() const { return !node; }
};

class SimpleParser
{
protected:
	_xmlDoc *doc;
	_xmlNode *root;

public:
	SimpleParser(void *data, int dataSize);
	virtual ~SimpleParser();

	Node GetNodeByName(Node parentNode, const std::string &name);
	std::vector <Node> GetNodesByName(Node parentNode, const std::string &name);
	std::string GetAttributeByName(Node node, const std::string &name);
	std::string GetValue(Node node);

	Node GetRootNode();
};

typedef std::vector <Node> Nodes;

}}}